/*
{
"状态":1,
"名称":"获取-部门信息",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"获取-部门信息",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/

declare @sql varchar(max)
declare @department_name varchar(100)
declare @company_key int
declare @where varchar(max)
set @department_name = '{department_name}'
set @company_key = '{company_key}'
set @where = ''
set @where += ' and company_key ='+convert(varchar,@company_key)
if (@department_name <>'')
begin
	set @where += ' and department_name like ''%'+@department_name+'%'''
end

set @sql = '
select department_key AS id,father_key as pid,
department_id , 
department_name ,remarks,convert(varchar(20),create_time,120)create_time,
convert(varchar(20),update_time,120)update_time from b_department where 1=1 {where} '
set @sql =replace(@sql,'{where}',@where)
 

exec(@sql)